package com.guet.niit.Login.controller.user;

import com.guet.niit.User.pojo.UserCar;
import com.guet.niit.util.UserBacktrack;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

public class ChargingCarListFxController implements Initializable {

    public static ChargingCarListFxController chargingCarListFxController;

    @FXML
    private ImageView backtrack;

    @FXML
    private ImageView carPhoto0;

    @FXML
    private Text carName0;

    @FXML
    private Text carNumber0;

    @FXML
    private Text status0;

    @FXML
    private ImageView carPhoto01;

    @FXML
    private Text carName01;

    @FXML
    private Text carNumber01;

    @FXML
    private Text status01;

    @FXML
    private ImageView carPhoto011;

    @FXML
    private Text carName011;

    @FXML
    private Text carNumber011;

    @FXML
    private Text status011;

    @FXML
    private ImageView carPhoto012;

    @FXML
    private Text carName012;

    @FXML
    private Text carNumber012;

    @FXML
    private Text status012;

    @FXML
    private ImageView carPhoto013;

    @FXML
    private Text carName013;

    @FXML
    private Text carNumber013;

    @FXML
    private Text status013;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        chargingCarListFxController = this;
    }

    /**
     * 返回用户菜单
     * @param mouseEvent
     */
    public void backtrack(MouseEvent mouseEvent) {
        UserBacktrack.backtrack(ChargingCarListFxController.class);
    }

    /**
     * 读取用户汽车信息
     */
    public void readUserCarInfo(ArrayList<UserCar> userCars){
        //根据记录的条数动态展示用户汽车信息条数
        carPhoto0.setImage(new Image("file:D:/img/"+userCars.get(0).getCarPhoto()));
        carName0.setText(userCars.get(0).getCarName());
        carNumber0.setText(userCars.get(0).getLicenseNumber());

        if (userCars.size()==2){
            carPhoto01.setImage(new Image("file:D:/img/"+userCars.get(1).getCarPhoto()));
            carName01.setText(userCars.get(1).getCarName());
            carNumber01.setText(userCars.get(1).getLicenseNumber());
        }
        if (userCars.size()==3){
            carPhoto011.setImage(new Image("file:D:/img/"+userCars.get(2).getCarPhoto()));
            carName011.setText(userCars.get(2).getCarName());
            carNumber011.setText(userCars.get(2).getLicenseNumber());
        }
        if (userCars.size()==4){
            carPhoto012.setImage(new Image("file:D:/img/"+userCars.get(3).getCarPhoto()));
            carName012.setText(userCars.get(3).getCarName());
            carNumber012.setText(userCars.get(3).getLicenseNumber());
        }if (userCars.size()==5){
            carPhoto013.setImage(new Image("file:D:/img/"+userCars.get(4).getCarPhoto()));
            carName013.setText(userCars.get(4).getCarName());
            carNumber013.setText(userCars.get(4).getLicenseNumber());
        }
    }
}
